﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using OpenSoftStore.BusinessLogic.Bill;
using OpenSoftStore.BusinessLogic.Member;
using OpenSoftStore.Client.Common;

namespace OpenSoftStore.Client.UIL.ManageReport
{
    public partial class ReportReturnMoney : UserControl
    {

        private MemberLogic LgcMember;
        private static ReportReturnMoney instance;
        public static ReportReturnMoney Instance
        {
            get
            {
                if (instance == null)
                {
                    instance = new ReportReturnMoney();
                }
                return instance;
            }
        }
        public ReportReturnMoney()
        {
            InitializeComponent();
            cbType.Text = "全部业务";
            cbState.Text = "全部";
            LgcMember = new MemberLogic();
            dtpFrom.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 00:00:00");
            dtpTo.Value = Convert.ToDateTime(DateTime.Now.ToString("yyyy-MM-dd") + " 23:59:59");
            this.Dock = DockStyle.Fill;
            dgvMemberOwed.AutoGenerateColumns = false;
            btnSearch_Click(null,null);
            //dgvMemberOwed.DataSource = billBll.GetBillReport("  where T_Bill.AddTime=#" + DateTime.Now.Date + "# ");
            SPACommon.SetDataGridStyle(dgvMemberOwed);
            SPACommon.ShowSummary(dgvMemberOwed);
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            DateTime from = dtpFrom.Value;
            DateTime to = dtpTo.Value;
            string type = cbType.Text;
            if (type == "全部业务") type = "";
            string state = cbState.Text;
            switch (state)
            {
                case "全部":
                    state = ">=";
                    break;
                case "未还清":
                    state = ">";
                    break;
                case "已还清":
                    state = "=";
                    break;
            }

            dgvMemberOwed.AutoGenerateColumns = false;
            dgvMemberOwed.DataSource = null;
            string whereStr = string.Format(" where (NeedPay - CashPay - BankPay - ValuePay - FavorMoney - AllReturn - ReturnFavor) {3} 0 and AddTime between #{0}# and #{1}# and Type like '%{2}%' ", from, to, type, state);
            dgvMemberOwed.DataSource = LgcMember.GetMemberOwedDataTable(whereStr); ;
        }

        private void glassButton1_Click(object sender, EventArgs e)
        {
            SPACommon.ExportToExcel(dgvMemberOwed, "欠款/还款统计");
        }
    }
}
